package com.gxa.modules.pc.sys.usermanager.controller;

import com.gxa.common.utils.Result;
import com.gxa.modules.pc.sys.usermanager.dto.RolePcDto;
import com.gxa.modules.pc.sys.usermanager.dto.UserPcDto;
import com.gxa.modules.pc.sys.usermanager.dto.UserSearchDto;
import com.gxa.modules.pc.sys.usermanager.service.RolePcService;
import com.gxa.modules.pc.sys.usermanager.service.UserPcService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName RolePcController
 * @Description
 * @Author Mr.YUAN
 * @Date 2022/11/17 20:28
 */
@Api(tags = "管理员管理")
@RestController
@RequestMapping("/admin")
public class UserPcController {

    @Autowired
    private UserPcService userPcService;

    @ApiOperation(value = "查询所有管理员",response = UserSearchDto.class)
    @PostMapping("/list")
    public Result list(@RequestBody UserSearchDto userSearchDto) {
        Result result = userPcService.list(userSearchDto);
        return result;
    }

    @ApiOperation(value = "新增管理员",response = UserPcDto.class)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "date",name = "userPcDto",value = "管理员信息",dataType = "String"),
            @ApiImplicitParam(paramType = "query",name = "roleId",value = "角色id",dataType = "int"),
    })
    @PostMapping("/add")
    public Result add(@RequestBody UserPcDto userPcDto,Integer roleId) {
        userPcService.add(userPcDto, roleId);
        return new Result().ok();
    }

    @ApiOperation(value = "修改管理员",response = UserPcDto.class)
    @PostMapping("/update")
    public Result update(@RequestBody UserPcDto userPcDto,Integer roleId) {
        userPcService.update(userPcDto, roleId);
        return new Result().ok();
    }

    @ApiOperation("删除管理员")
    @PutMapping("/delete")
    public Result delete(List<Integer> ids) {
        userPcService.delete(ids);
        return new Result().ok();
    }

}